package com.zryc.shop.sms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.sms.service.ICouponHistoryService;
import com.zryc.shop.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 优惠券使用、领取历史表 前端控制器
 * </p>
 *
 * @author LiYe
 * @since 2023-02-13
 */
@RestController
@RequestMapping("/sms/couponHistory")
@Api(tags = "优惠券使用历史")
public class CouponHistoryController {
    @Autowired
    private ICouponHistoryService couponHistoryService;
    @GetMapping("/list")
    @ApiOperation("查询使用记录")
    public ResponseResult list(@RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                               @RequestParam(defaultValue = "10") @ApiParam(value = "每页显示条数", required = true) Integer pageSize,
                               @RequestParam @ApiParam(value = "优惠券ID", required = true) Long couponId,
                               @RequestParam(required = false) @ApiParam(value = "优惠券使用状态", allowableValues = "0,1") Integer useStatus,
                               @RequestParam(required = false) @ApiParam(value = "订单编号") String orderSn) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("coupon_id", couponId);
        if (useStatus!=null) {
            queryWrapper.eq("use_status", useStatus);
        }
        if (!StringUtils.isEmpty(orderSn)) {
            queryWrapper.eq("order_sn", orderSn);
        }
        Page page = new Page(pageNum, pageSize);
        couponHistoryService.page(page, queryWrapper);
        return new ResponseResult(200, "查询完成", page);
    }
}
